﻿using System;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

namespace JQMergeFramework
{
    public class UIMarqueeItem : MonoBehaviour
    {
        public Text txtMsg;

        public RectTransform mRect;

        public RectTransform txtRect;
        
        public void Refresh (MarqueeCfg marqueeInfo,BhvEasyPool objPool,Vector3 startPos,Vector3 endPos) {
            txtMsg.text = marqueeInfo.descriptions;
            
            LayoutRebuilder.ForceRebuildLayoutImmediate(txtRect);
            
            
            mRect.sizeDelta = new Vector2(txtRect.rect.size.x+50, mRect.rect.size.y);
            txtMsg.transform.localPosition = Vector3.zero;
            this.transform.localPosition = startPos + new Vector3(txtRect.rect.size.x,0,0);


            float t = (startPos.x + txtRect.rect.size.x) / 100;
            
            this.transform.DOLocalMoveX(endPos.x - txtRect.rect.size.x, t).SetEase(Ease.Linear).OnComplete(() =>
            {
                objPool.Put(this.gameObject);
            });
        }
    }
    
}